package com.example.common.event;

import java.io.Serializable;
import java.util.Objects;

/**
 * 操作日志事件
 */
public class OperationLogEvent implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long userId;
    private String action;
    private String ip;
    private String detail;

    // 无参构造器 (@NoArgsConstructor)
    public OperationLogEvent() {
    }

    // 全参构造器 (@AllArgsConstructor)
    public OperationLogEvent(Long userId, String action, String ip, String detail) {
        this.userId = userId;
        this.action = action;
        this.ip = ip;
        this.detail = detail;
    }

    // Builder模式实现 (@Builder)
    public static OperationLogEventBuilder builder() {
        return new OperationLogEventBuilder();
    }

    public static class OperationLogEventBuilder {
        private Long userId;
        private String action;
        private String ip;
        private String detail;

        OperationLogEventBuilder() {
        }

        public OperationLogEventBuilder userId(Long userId) {
            this.userId = userId;
            return this;
        }

        public OperationLogEventBuilder action(String action) {
            this.action = action;
            return this;
        }

        public OperationLogEventBuilder ip(String ip) {
            this.ip = ip;
            return this;
        }

        public OperationLogEventBuilder detail(String detail) {
            this.detail = detail;
            return this;
        }

        public OperationLogEvent build() {
            return new OperationLogEvent(userId, action, ip, detail);
        }
    }

    // Getter/Setter (@Data)
    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    // equals() 和 hashCode() (@Data)
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        OperationLogEvent that = (OperationLogEvent) o;
        return Objects.equals(userId, that.userId) &&
                Objects.equals(action, that.action) &&
                Objects.equals(ip, that.ip) &&
                Objects.equals(detail, that.detail);
    }

    @Override
    public int hashCode() {
        return Objects.hash(userId, action, ip, detail);
    }

    // toString() (@Data)
    @Override
    public String toString() {
        return "OperationLogEvent{" +
                "userId=" + userId +
                ", action='" + action + '\'' +
                ", ip='" + ip + '\'' +
                ", detail='" + detail + '\'' +
                '}';
    }
}